/************************************
 * Package: RGcpp					*
 * Authors: Rui Eduardo Gouveia Gil	*
 * Date: 2010						*
 ************************************/
#ifndef __RGCPP_JOBQUEUE_H__
#define __RGCPP_JOBQUEUE_H__

#include <deque>
#include <queue>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>

#include "rgcpp/sys/Job.h"

namespace rgcpp
{

struct JobLess
{
	bool operator() (const boost::shared_ptr<Job>& x, const boost::shared_ptr<Job>& y) const
	{
		return x->getExecuteTime() > y->getExecuteTime();
	}
};

class JobQueue
{
	private:
		bool running;
		boost::mutex mut;
		boost::mutex io_mutex;
		boost::condition_variable cond;
		std::priority_queue<boost::shared_ptr<Job>,std::deque<boost::shared_ptr<Job> >, JobLess> queue;

	public:
		JobQueue();
		virtual ~JobQueue();

		void release();

		void addJob(boost::shared_ptr<Job> job);
		boost::shared_ptr<Job> getJob();

		int size();
};

}

#endif
